<style type="text/css">          
td{padding:0;margin:0;}
</style>
<div id="result">
<?php echo $this->Session->flash(); ?>
<div class="div_header1"><?php if(isset($this->data['Cat']['Category']['category_name'])) echo __("Sizes for ").$this->data['Cat']['Category']['category_name'];?></div>
<br style="clear:both;">	
<table align="center" border="0" cellpadding="0" width="250">
	
	
	<?php 
	if($this->data['Size']):
		foreach($this->data['Size'] as $size):
	?>
	<tr>
		<td width="25">
			<?php $checked="";
			if($this->data['Cat']['Category']['sizes_dropdown'] && in_array($size['Sizetitle']['id'],$this->data['Cat']['Category']['sizes_dropdown']))				
				$checked=' checked="checked"';
			else
				$checked="";
			?>
			<input name="setdropdown[]" type="checkbox" value="<?php echo $size['Sizetitle']['id'];?>" <?php echo $checked;?> />
		</td>
		<td width="25"><a href="javascript:void(0);"  action="deletesizelabel" controller="add_category" ElmID2="<?php echo $this->data['Cat']['Category']['id'];?>" ElmID="<?php echo $size['Sizetitle']['id'];?>" onclick="deleteValue(this)"><?php echo $this->Html->image("close-btn.png", array("alt" => "Delete",'border'=>'0'));?></a></td>
		<td width="200"><?php echo $size['Sizetitle']['size_title'];?></td>
	</tr>
	<tr>
		<td width="25">&nbsp;</td>
		<td width="25">&nbsp;</td>
		<td width="200">
			<form method="post" id="addSizeValue_<?php echo $size['Sizetitle']['id'];?>"  name="addSizeValue_<?php echo $size['Sizetitle']['id'];?>" action="javascript:void(0);">
				<table align="left" cellpadding="0" cellspacing="0" border="0" width="200" id="SizeValueTable_<?php echo $size['Sizetitle']['id'];?>">
				<?php if($size['Sizevalue']):
					$total_size_value=count($size['Sizevalue']);
					$i=1;
					foreach($size['Sizevalue'] as $Sizevalue):	
				?>
				<tr>
					<td width="10">&nbsp;</td>
					<td width="10" align="center">
					<?php 
					if($total_size_value==$i)
						echo $this->Html->image("link-line-02.gif", array("alt" => "Line",'border'=>'0'));
					else
						echo $this->Html->image("link-line-01.gif", array("alt" => "Line",'border'=>'0'));				
					?>
					</td>
					<td width="10"><?php echo $this->Html->image("arrow-black.gif", array("alt" => "Line",'width'=>'10','height'=>'7','border'=>'0'));?></td>
					<td width="50"><?php echo $Sizevalue['size_value'];?></td>
					<td width="120">
						<a href="javascript:void(0);" action="deletesizevalue" controller="add_category" ElmID2="<?php echo $this->data['Cat']['Category']['id'];?>" ElmID="<?php echo $Sizevalue['id'];?>" valueID="<?php echo $Sizevalue['id'];?>"  onclick="deleteValue(this)" class="deleteValue1"><?php echo $this->Html->image("close-btn.png", array("alt" => "Delete",'border'=>'0'));?></a>
					</td>
				</tr>
				<?php $i++; endforeach; endif;?>			
						
				</table>  
				<table align="left" cellpadding="0" cellspacing="0" border="0"width="200">
					  <tr>
						<td width="10">&nbsp;</td>
						<td colspan="140" valign="top"><input type="hidden"  name="data[sizetitle_id]" value="<?php echo $size['Sizetitle']['id'];?>" />
						<?php echo $this->Form->input('size_value',array('label'=>false,'size'=>30,'id'=>'size_value','class'=>"required", 'title'=>"Enter size value here")); ?></td>
						<td width="50" valign="top"><input name="Add" sizeID="<?php echo $size['Sizetitle']['id'];?>" catID="<?php echo $this->data['Cat']['Category']['id'];?>" type="button" value="Add" /></td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
	<tr>
	 <td colspan="3" height="10">&nbsp;</td>
	</tr>
	<?php endforeach;?>
	
	<tr>
	 <td colspan="3" align="left"><a href="javascript:void(0);" id="dropdown">Set in one dropdown</a></td>
	</tr>
	<?php endif;?>
	<tr>
		<td colspan="3" valign="top">
		<form method="post" id="addSize"  name="addSize" action="<?php echo Configure::read('base_url')."add_category/sizes/".$this->data['Cat']['Category']['id'];?>">
		<table cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td width="25">&nbsp;</td>
				<td valign="top">
					<input type="hidden"  name="data[category_id]" id="catid" value="<?php echo $this->data['Cat']['Category']['id'];?>" />
					<?php echo $this->Form->input('size_title',array('label'=>false,'size'=>30,'id'=>'size_title','class'=>"required", 'title'=>"Enter size title here")); ?>
				</td>
				<td  valign="top"><input type="submit" name="submit" value="Add" /></td>
			</tr>
		</table>
		</form>
		</td>
	</tr>	
</table>
</div>
<?php  echo $html->script(array("jquery.min.js","jquery.form.js","jquery.validate.js","jquery.pagination.js","jquery.tablesorter.min.js","jquery.tablednd.js")); ?>	 
<script type="text/javascript">  
 jQuery(document).ready(function(){
 var v = jQuery("#addSize").validate({
			submitHandler: function(form) {				
				jQuery(form).ajaxSubmit({				
					target: "#result"
				});
			}
		});
		
jQuery('a#dropdown').click(function(){
	catID=jQuery('input[name="data[category_id]"]').val();	
	data=jQuery('input[type="checkbox"]').serialize();
	if(data!=""){
		jQuery.ajax({
				type: 'post',
				url: baseurl+"add_category/setdropdown/"+catID,			
				data: data,
				dataType: 'json',
				success:function(data){
					if(data.message=="Yes")
						alert("Items have successfully set in a dropdown.");						
					else	
						alert("Items could not be set in a dropdown. Please, try again.");						
				}	
			});
		return false;	
	}	
	else{
		alert("You have to select the items to set in a dropdown.");
	}
});		

jQuery("tr td a.deleteLabel").click(function(){
		if(confirm("Are you sure you want to delete this?")){					
			sizeID=jQuery(this).attr("sizeID");			
			//lastTRIndex=jQuery("#SizeValueTable_"+sizeID+" tr:last").index();		
			currentTRIndex=jQuery(this).parent().parent().index();		
			//alert(currentTRIndex);
			jQuery.ajax({
				type: 'get',
				url: baseurl+"add_category/deletesizelabel/"+sizeID,			
				dataType: 'json',
				success: function(data){
					if(data.message=="Yes")
					{
						jQuery(this).parent().parent().next().remove();						
						jQuery(this).parent().parent().remove();						
						
						
						//jQuery("tr td a.deleteLabel:eq("+currentTRIndex+")").parent().parent().hide().fadeOut("slow");						
						//jQuery("tr td a.deleteLabel:eq("+currentTRIndex+")").parent().parent().next().hide().fadeOut("slow");						
						return false;
					}				
					return false;
				}			
			});
		}
			
	});
	
	jQuery("tr td a.deleteValue").live('click',function(){
	
		if(confirm("Are you sure you want to delete this?")){		
			catID=jQuery(this).attr("catID");
			valueID=jQuery(this).attr("valueID");
			sizeID=jQuery(this).attr("sizeID");
			lastTRIndex=jQuery("#SizeValueTable_"+sizeID+" tr:last").index();		
			currentTRIndex=jQuery(this).parent().parent().index();		
			
			jQuery.ajax({
				type: 'get',
				url: baseurl+"add_category/deletesizevalue/"+valueID+"/"+catID,			
				dataType: 'html'							
			});
			return false;
		}	
	});	
	
	jQuery(":button").click(function(){
		catID=jQuery(this).attr("catID");
		sizeID=jQuery(this).attr("sizeID");	
		
		data = jQuery("form#addSizeValue_"+sizeID).serialize();	
		jQuery.ajax({
			type: 'POST',
			url: baseurl+"add_category/addsizevalue/"+sizeID,			
			data: data,
			dataType: 'json',
			success: function(data){
				
				if(data.message=="Yes")
				{
					jQuery("form#addSizeValue_"+sizeID+" input[type='text']").val("");
					jQuery("#SizeValueTable_"+sizeID+" tr:last").find('td').first().next().html('<img src="<?php echo Configure::read('base_url');?>/img/link-line-01.gif" alt="Line" border="0">');
					html='<tr><td width="10">&nbsp;</td><td width="10" align="center"><img src="<?php echo Configure::read('base_url');?>/img/link-line-02.gif" alt="Line" border="0"></td><td width="10"><img src="<?php echo Configure::read('base_url');?>img/arrow-black.gif" alt="Line" width="10" height="7" border="0"></td><td width="50">'+data.value+'</td><td width="120"><a href="javascript:void(0);" action="deletesizevalue" controller="add_category" ElmID2="'+catID+'" ElmID="'+data.valueID+'"   onclick="deleteValue(this)" class="deleteValue1"><img src="<?php echo Configure::read('base_url');?>img/close-btn.png" alt="Delete" border="0"></a></td></tr>';
					jQuery("#SizeValueTable_"+sizeID).append(html);				
				}
				else{
					jQuery("form#addSizeValue_"+sizeID+" input[type='text']").addClass("error");
					html='<label for="size_title" generated="true" class="error">Enter size value here</label>';
					jQuery("form#addSizeValue_"+sizeID+" input[type='text']").after(html);				
				}
				return false;
			}			
		});
	});	
});
function deleteValue(param){
		if(confirm("Are you sure you want to delete this?")){		
			showPop(param);
			//return false;
		}
		else return false;	
	}
</script>